#!/bin/bash
read -p "服务名：" servername
serverpid=$(netstat -tlunp |  grep $servername| head -n 1 | awk '{print $7}' | awk -F/ '{print $1}') 2> /dev/null
serverport=$(netstat -tlunp |  grep $servername | head -n 1 | awk '{print $4}' | awk -F: '{print $2}') 2> /dev/null
serverstatus=$(systemctl status $servername | head -n 3 | tail -n 1 | awk '{print  $3}') 2> /dev/null
starttime=$(systemctl show $servername --property=ActiveEnterTimestamp | awk -F= '{print $2}') 2> /dev/null

if [ "$serverstatus" == '(running)' ]; then
    echo "服务名称：$servername, PID：$serverpid, 端口：$serverport, 启动时间：$starttime"
else
    echo "服务未启动或找不到"
fi

